package com.shenzhen.horselive.ui.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.shenzhen.horselive.Constants;
import com.shenzhen.horselive.MainActivity;
import com.shenzhen.horselive.R;
import com.shenzhen.horselive.User;
import com.shenzhen.horselive.base.AppBarActivity;
import com.shenzhen.horselive.base.BaseActivity;
import com.shenzhen.horselive.databinding.ActivityLoginBinding;
import com.shenzhen.horselive.databinding.ActivityMainBinding;
import com.shenzhen.horselive.ui.dialog.LoginDialog;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

public class LoginActivity extends BaseActivity {
    ActivityLoginBinding binding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityLoginBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        //初始化
//        if (User.get().isLogin())
//        {
//           //有登录状态
//           startActivity(new Intent(this, MainActivity.class));
//           finish();
//        }else
//        {
        tranFullImmbar();
        initViews();
//        }
    }

    LoginDialog  dialog;
    private void initViews() {
       binding.imgWeixinLogin.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               //直接登录
               openweixin();
//               if (dialog==null)
//               {
//                   dialog = new LoginDialog(LoginActivity.this);
//                   dialog.setConfirm(new View.OnClickListener() {
//                       @Override
//                       public void onClick(View v) {
////
//                           openweixin();
//                           dialog.dismiss();
//                       }
//                   });
//                   dialog.setCancel(new View.OnClickListener() {
//                       @Override
//                       public void onClick(View v) {
//                           dialog.dismiss();
//                       }
//                   });
//               }
//               dialog.show();
           }
       });

    }

    //打开微信
    private void openweixin() {
        IWXAPI  api = WXAPIFactory.createWXAPI(this, Constants.WECHAT_APPID);
        if (api!=null&&api.isWXAppInstalled())
        {
         SendAuth.Req req = new SendAuth.Req();
         req.scope = "snsapi_userinfo";
         api.sendReq(req);
        }

    }
}